version 8.2
capture clear
capture log close
set more off
set mem 5000m
set mat 2000

set scheme s2mono

use "Enterprise surveys_judicial_reforms_standardized dataset.dta", replace


sum DJ4g1m
centile(DJ4g1m), centile(50)
display `r(c_1)'
*hist DJ4g1, percent

label variable h7a "Judicial efficiency"

replace va_perwo_ppp_trim1 =va_perwo_ppp_trim1 /1000
label variable va_perwo_ppp_trim1 "Value added per worker (Thousand dollars)"
local lab : var label va_perwo_ppp_trim1

keep if dataset==1


***polityIV:
centile(polity2) if post==0, centile(50)
display `r(c_1)'
*Median is 7

gen Polity_below=1 if polity2<=`r(c_1)'
replace  Polity_below=0 if polity2>`r(c_1)'&polity2!=.
gen Polity_above=1 if polity2>`r(c_1)'&polity2!=.
replace Polity_above=0 if polity2<=`r(c_1)'&polity2!=.
*So Polity_above is 8,9,10
*We include the median in Polity_below to get approximately balanced samples 

ren Polity_above Polity_IV

label define Below_Above 0 "Below Median" 1 "Above Median", modify
label values Polity_IV Below_Above


***sueing_condition
*centile(sueing_condition) if post==0, centile(50)
*display `r(c_1)'
*Median is 0.07
*But here the obvious dicotomoy is <0 and >0

gen sueing_condition_pos=1 if sueing_condition>=0
replace sueing_condition_pos=0 if sueing_condition<0

label define Negative_Positive 0 "Suing condition: Negative" 1 "Suing condition: Positive", modify
label values sueing_condition_pos Negative_Positive


save "Data_heterogeneous.dta", replace
	

clear
use "Data_heterogeneous.dta", replace

collapse (mean) mean_h7a=h7a (mean) mean_va_perwo_ppp_trim1=va_perwo_ppp_trim1, by(reform_dum1 post DJ4g1m sueing_condition_pos)

graph twoway (scatter mean_va_perwo_ppp_trim1 post if DJ4g1m==1 & reform_dum1==1 & sueing_condition_pos==0, connect(direct) lcolor(black) lwidth(thick) msymbol(O) mcolor(black) msize(large)) ///
(scatter mean_va_perwo_ppp_trim1 post if DJ4g1m==1 & reform_dum1==0 & sueing_condition_pos==0, connect(direct) lcolor(black) lpattern(dash) lwidth(thick) msymbol(O) mcolor(black) msize(large)) ///
, legend(order(1 2) label(1 "Judicial Reform") label(2 "No Judicial Reform")) xtitle("") xscale(range(-0.2 1.2)) xlabel(0(1)1 0 "Before" 1 "After") ytitle("Value added per worker In ,000 USD PPP") title("Specific-Negative Suing Condition")
graph export "Figure E1a graph_va_perwo_ppp_trim1_Reform_Specific_negative_sueing_condition.png", replace

graph twoway (scatter mean_va_perwo_ppp_trim1 post if DJ4g1m==0 & reform_dum1==1 & sueing_condition_pos==0, connect(direct) lcolor(black) lwidth(thick) msymbol(O) mcolor(black) msize(large)) ///
(scatter mean_va_perwo_ppp_trim1 post if DJ4g1m==0 & reform_dum1==0 & sueing_condition_pos==0, connect(direct) lcolor(black) lpattern(dash) lwidth(thick) msymbol(O) mcolor(black) msize(large)) ///
, legend(order(1 2) label(1 "Judicial Reform") label(2 "No Judicial Reform")) xtitle("") xscale(range(-0.2 1.2)) xlabel(0(1)1 0 "Before" 1 "After") ytitle("Value added per worker In ,000 USD PPP") title("Generic-Negative Suing Condition")
graph export "Figure E1b graph_va_perwo_ppp_trim1_Reform_Generic_negative_sueing_condition.png", replace

graph twoway (scatter mean_va_perwo_ppp_trim1 post if DJ4g1m==1 & reform_dum1==1 & sueing_condition_pos==1, connect(direct) lcolor(black) lwidth(thick) msymbol(O) mcolor(black) msize(large)) ///
(scatter mean_va_perwo_ppp_trim1 post if DJ4g1m==1 & reform_dum1==0 & sueing_condition_pos==0, connect(direct) lcolor(black) lpattern(dash) lwidth(thick) msymbol(O) mcolor(black) msize(large)) ///
, legend(order(1 2) label(1 "Judicial Reform") label(2 "No Judicial Reform")) xtitle("") xscale(range(-0.2 1.2)) xlabel(0(1)1 0 "Before" 1 "After") ytitle("Value added per worker In ,000 USD PPP") title("Specific-Positive Suing Condition")
graph export "Figure E1c graph_va_perwo_ppp_trim1_Reform_Specific_positive_sueing_condition.png", replace

graph twoway (scatter mean_va_perwo_ppp_trim1 post if DJ4g1m==0 & reform_dum1==1 & sueing_condition_pos==1, connect(direct) lcolor(black) lwidth(thick) msymbol(O) mcolor(black) msize(large)) ///
(scatter mean_va_perwo_ppp_trim1 post if DJ4g1m==0 & reform_dum1==0 & sueing_condition_pos==0, connect(direct) lcolor(black) lpattern(dash) lwidth(thick) msymbol(O) mcolor(black) msize(large)) ///
, legend(order(1 2) label(1 "Judicial Reform") label(2 "No Judicial Reform")) xtitle("") xscale(range(-0.2 1.2)) xlabel(0(1)1 0 "Before" 1 "After") ytitle("Value added per worker In ,000 USD PPP") title("Generic-Positive Suing Condition")
graph export "Figure E1d graph_va_perwo_ppp_trim1_Reform_Generic_positive_sueing_condition.png", replace


clear
use "Data_heterogeneous.dta", replace

collapse (mean) mean_h7a=h7a (mean) mean_va_perwo_ppp_trim1=va_perwo_ppp_trim1, by(reform_dum1 post DJ4g1m Polity_IV)

graph twoway (scatter mean_va_perwo_ppp_trim1 post if DJ4g1m==1 & reform_dum1==1 & Polity_IV==0, connect(direct) lcolor(black) lwidth(thick) msymbol(O) mcolor(black) msize(large)) ///
(scatter mean_va_perwo_ppp_trim1 post if DJ4g1m==1 & reform_dum1==0 & Polity_IV==0, connect(direct) lcolor(black) lpattern(dash) lwidth(thick) msymbol(O) mcolor(black) msize(large)) ///
, legend(order(1 2) label(1 "Judicial Reform") label(2 "No Judicial Reform")) xtitle("") xscale(range(-0.2 1.2)) xlabel(0(1)1 0 "Before" 1 "After") ytitle("Value added per worker In ,000 USD PPP") title("Specific-Below Median Polity IV")
graph export "Figure E2a graph_va_perwo_ppp_trim1_Reform_Specific_Below_Median_Polity_IV.png", replace

graph twoway (scatter mean_va_perwo_ppp_trim1 post if DJ4g1m==0 & reform_dum1==1 & Polity_IV==0, connect(direct) lcolor(black) lwidth(thick) msymbol(O) mcolor(black) msize(large)) ///
(scatter mean_va_perwo_ppp_trim1 post if DJ4g1m==0 & reform_dum1==0 & Polity_IV==0, connect(direct) lcolor(black) lpattern(dash) lwidth(thick) msymbol(O) mcolor(black) msize(large)) ///
, legend(order(1 2) label(1 "Judicial Reform") label(2 "No Judicial Reform")) xtitle("") xscale(range(-0.2 1.2)) xlabel(0(1)1 0 "Before" 1 "After") ytitle("Value added per worker In ,000 USD PPP") title("Generic-Below Median Polity IV")
graph export "Figure E2b graph_va_perwo_ppp_trim1_Reform_Generic_Below_Median_Polity_IV.png", replace

graph twoway (scatter mean_va_perwo_ppp_trim1 post if DJ4g1m==1 & reform_dum1==1 & Polity_IV==1, connect(direct) lcolor(black) lwidth(thick) msymbol(O) mcolor(black) msize(large)) ///
(scatter mean_va_perwo_ppp_trim1 post if DJ4g1m==1 & reform_dum1==0 & Polity_IV==0, connect(direct) lcolor(black) lpattern(dash) lwidth(thick) msymbol(O) mcolor(black) msize(large)) ///
, legend(order(1 2) label(1 "Judicial Reform") label(2 "No Judicial Reform")) xtitle("") xscale(range(-0.2 1.2)) xlabel(0(1)1 0 "Before" 1 "After") ytitle("Value added per worker In ,000 USD PPP") title("Specific-Above Median Polity IV")
graph export "Figure E2c graph_va_perwo_ppp_trim1_Reform_Specific_Above_Median_Polity_IV.png", replace

graph twoway (scatter mean_va_perwo_ppp_trim1 post if DJ4g1m==0 & reform_dum1==1 & Polity_IV==1, connect(direct) lcolor(black) lwidth(thick) msymbol(O) mcolor(black) msize(large)) ///
(scatter mean_va_perwo_ppp_trim1 post if DJ4g1m==0 & reform_dum1==0 & Polity_IV==0, connect(direct) lcolor(black) lpattern(dash) lwidth(thick) msymbol(O) mcolor(black) msize(large)) ///
, legend(order(1 2) label(1 "Judicial Reform") label(2 "No Judicial Reform")) xtitle("") xscale(range(-0.2 1.2)) xlabel(0(1)1 0 "Before" 1 "After") ytitle("Value added per worker In ,000 USD PPP") title("Generic-Above Median Polity IV")
graph export "Figure E2d graph_va_perwo_ppp_trim1_Reform_Generic_Above_Median_Polity_IV.png", replace










